﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace QLDonDatHang
{
    public partial class Form_Login2 : MaterialSkin.Controls.MaterialForm
    {
        Form frm_NewAccout,frm_Home;
        ConnectToSQLSever a = new ConnectToSQLSever();
        SqlConnection database = new SqlConnection(@"Data Source=NGUYENVANPHUC\SQLEXPRESS;Initial Catalog=QL_BANHANG_GIOCHA;Integrated Security=True;Connect Timeout=15;Encrypt=False;TrustServerCertificate=True;ApplicationIntent=ReadWrite;MultiSubnetFailover=False");
        public Form_Login2()
        {
            InitializeComponent();
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            
        }

        private void bt_Login_Click(object sender, EventArgs e)
        {
            if (txt_Uses.Text.ToString().Equals("")||txtPassword.Text.ToString().Equals(""))
            {
                MessageBox.Show("Vui lòng nhập tài khoản!","Thông báo",MessageBoxButtons.OK,MessageBoxIcon.Stop);

            }else if(a.checkTaiKhoan(txt_Uses.Text.ToString()))
            {
                if (a.checkTaiKhoan(txt_Uses.Text.ToString(), txtPassword.Text.ToString()))
                {
                    this.Hide();
                    frm_Home = new Form_Home();
                    frm_Home.Show();
                }else
                MessageBox.Show("Mật khẩu sai!","Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            else
            {
                MessageBox.Show("Tài khoản không tồn tại!","Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }

        private void bt_Exit_Click(object sender, EventArgs e)
        {
           
            if (MessageBox.Show("Xác nhận thoát ?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
            {
                Application.Exit();
            }
        }

        private void Form_Login2_Load(object sender, EventArgs e)
        {

        }

        private void txt_Uses_Enter(object sender, EventArgs e)
        {
            //txtPassword.Focus();
        }

        private void lb_CreatAccout_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            frm_NewAccout = new Form_CreatAccout();
            frm_NewAccout.ShowDialog();
        }
    }
}
